package com.Sing.VerifyCode;

import java.awt.*;
import java.util.Random;

public class VerifyCodeBuild {

    private static final char[] CODE_ARRAY = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J',
            'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
            'X', 'Y', 'Z', '2', '3', '4', '5', '6', '7', '8', '9' };

    private static final char[] NUMBER_ARRAY = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };

    private static Random random = new Random();

    // 生成随机字符
    public static String randomString( int length ){
        StringBuilder stringBuilder = new StringBuilder();

        for ( int i = 0; i < length; i++ ){
            stringBuilder.append( CODE_ARRAY[ random.nextInt( CODE_ARRAY.length ) ] );
        }

        return stringBuilder.toString();
    }

    // 生成随机数字
    public static String randomInteger( int length ){
        StringBuilder stringBuilder = new StringBuilder();

        for ( int i = 0; i < length; i++ ){
            stringBuilder.append( NUMBER_ARRAY[ random.nextInt( NUMBER_ARRAY.length ) ] );
        }

        return stringBuilder.toString();
    }

    // 生成随机颜色
    public static Color randomColor( int fc, int bc ){
        int f = fc;
        int b = bc;
        Random random = new Random();
        if (f > 255) {
            f = 255;
        }
        if (b > 255) {
            b = 255;
        }

        return new Color(f + random.nextInt(b - f), f + random.nextInt(b - f), f + random.nextInt(b - f));
    }

    public static int nextInt(int bound) {
        return random.nextInt(bound);
    }

}
